package com.fmn.dots_final_i_hope;


import com.fmn.dots_final_i_hope.MainActivity;
import com.fmn.dots_final_i_hope.R;
import com.fmn.dots_final_i_hope.R.id;
import com.fmn.dots_final_i_hope.R.layout;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewDebug.IntToString;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MenuActivity extends Activity implements OnClickListener{


	private ImageView startButton;
	private ImageView tableSizeButton;
	private ImageView p1ChoseButton;
	private ImageView p2ChoseButton;

	//PlayerControl.choosenCol
	//PlayerControl.choosenRow
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_menu);

		
		tableSizeButton = (ImageView) findViewById(R.id.tableSizeButton);
		tableSizeButton.setOnClickListener(this);
		
		startButton = (ImageView) findViewById(R.id.startButton);
		startButton.setOnClickListener(this);

		p1ChoseButton = (ImageView) findViewById(R.id.p1color);
		p1ChoseButton.setOnClickListener(this);
		
		p2ChoseButton = (ImageView) findViewById(R.id.p2color);
		p2ChoseButton.setOnClickListener(this);
		
	}


	@Override
	public void onClick(View v) {


		switch (v.getId()){
			case R.id.startButton: 
			{
				startActivity(new Intent(MenuActivity.this, PlayerVsComputerActivity.class));
				//starts with 3/3 

				break;
			}
			case R.id.tableSizeButton:
			{
				
				//setting 3/3,4/4,5/5
				showTableSizeDialog();
				break;
			}
			case R.id.p1color:
			{

				showPlayer1ColorDialog();
				break;
			}
			case R.id.p2color:
			{

				showPlayer2ColorDialog();
				break;
			}
	
		}
		
	}
	
	
	
	private void showTableSizeDialog(){
		
		
		AlertDialog.Builder dialoBuilder = new AlertDialog.Builder(this);
		final String[] sizes = {"3/3","3/4","4/4","4/5","5/5"};
		dialoBuilder.setTitle("Set Table Size");
		dialoBuilder.setItems(sizes, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {

				//Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
				Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
		
				if (sizes[which]=="3/3"){
					PlayerControl.choosenCol=3;
					PlayerControl.choosenRow=3;
					
				} else if (sizes[which]=="3/4") {
					PlayerControl.choosenCol=4;
					PlayerControl.choosenRow=3;
				
				}else if (sizes[which]=="4/4") {
					PlayerControl.choosenCol=4;
					PlayerControl.choosenRow=4;
				
				}else if (sizes[which]=="4/5") {
					PlayerControl.choosenCol=5;
					PlayerControl.choosenRow=4;
					
				}else if (sizes[which]=="5/5") {
					PlayerControl.choosenCol=5;
					PlayerControl.choosenRow=5;
					
				}
				Log.d("stringToIntFirstNumber ", " "+PlayerControl.choosenCol);
				Log.d("stringToIntLastNumber ", " "+PlayerControl.choosenRow);
				
			}
		});
		AlertDialog alertDialog = dialoBuilder.create();
		alertDialog.show();
		
		
	}
	
	
	
	
	
	
	
	
	private void showPlayer1ColorDialog(){
		
		
		AlertDialog.Builder dialoBuilder = new AlertDialog.Builder(this);
		final String[] sizes = {"GREEN","PINK","PURPLE","ORANGE","SILVER", "RED"};
		dialoBuilder.setTitle("Set Table Size");
		dialoBuilder.setItems(sizes, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {

				//Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
				Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
		
				if (sizes[which]=="GREEN"){
					PlayerControl.chosenPic1 = (R.drawable.taken_square1);
					
				} else if (sizes[which]=="PINK") {
					PlayerControl.chosenPic1 = (R.drawable.taken_square2);
				
				}else if (sizes[which]=="PURPLE") {
					PlayerControl.chosenPic1 = (R.drawable.taken_square3);
				
				}else if (sizes[which]=="ORANGE") {
					PlayerControl.chosenPic1 = (R.drawable.taken_square4);
					
				}else if (sizes[which]=="SILVER") {
					PlayerControl.chosenPic1 = (R.drawable.taken_square5);
					
				}else if (sizes[which]=="RED") {
					PlayerControl.chosenPic1 = (R.drawable.taken_square6);
					
				}
				
			}
		});
		AlertDialog alertDialog = dialoBuilder.create();
		alertDialog.show();
	}	
		
		private void showPlayer2ColorDialog(){
			
			
			AlertDialog.Builder dialoBuilder = new AlertDialog.Builder(this);
			final String[] sizes = {"GREEN","PINK","PURPLE","ORANGE","SILVER", "RED"};
			dialoBuilder.setTitle("Set Table Size");
			dialoBuilder.setItems(sizes, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {

					//Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
					Toast.makeText(getApplicationContext(), sizes[which], Toast.LENGTH_SHORT).show();
			
					if (sizes[which]=="GREEN"){
						PlayerControl.chosenPic2 = (R.drawable.taken_square1);
						
					} else if (sizes[which]=="PINK") {
						PlayerControl.chosenPic2 = (R.drawable.taken_square2);
					
					}else if (sizes[which]=="PURPLE") {
						PlayerControl.chosenPic2 = (R.drawable.taken_square3);
					
					}else if (sizes[which]=="ORANGE") {
						PlayerControl.chosenPic2 = (R.drawable.taken_square4);
						
					}else if (sizes[which]=="SILVER") {
						PlayerControl.chosenPic2 = (R.drawable.taken_square5);
						
					}else if (sizes[which]=="RED") {
						PlayerControl.chosenPic2 = (R.drawable.taken_square6);
						
					}
					
				}
			});
			AlertDialog alertDialog = dialoBuilder.create();
			alertDialog.show();
		
		
	}
	
}
